﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration
Imports System.Data.Common


Public Class frmQuanLyNXB
    Dim ds As New DataSet
    Dim db As Database = EnterpriseLibraryContainer.Current.GetInstance(Of Database)()

    Private Sub frmQuanLyNXB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ds = db.ExecuteDataSet(CommandType.Text, "SELECT * FROM NhaXuatBan")
        ds.Tables(0).TableName = "NXB"
        dgvNXB.DataSource = ds.Tables(0)
    End Sub

    Private Sub btLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLuu.Click
        Try
            Dim insert As DbCommand = Nothing
            insert = db.GetStoredProcCommand("insertNXB")
            db.AddInParameter(insert, "tennxb", DbType.String, "TenNXB", DataRowVersion.Current)
            db.AddInParameter(insert, "diachi", DbType.String, "DiaChi", DataRowVersion.Current)
            db.AddInParameter(insert, "sodt", DbType.String, "SoDT", DataRowVersion.Current)
            db.AddInParameter(insert, "email", DbType.String, "Email", DataRowVersion.Current)

            Dim delete As DbCommand = Nothing
            delete = db.GetStoredProcCommand("deleteNXB")
            db.AddInParameter(delete, "manxb", DbType.Int32, "MaNXB", DataRowVersion.Current)

            Dim update As DbCommand = Nothing
            update = db.GetStoredProcCommand("updateNXB")
            db.AddInParameter(update, "manxb", DbType.Int32, "MaNXB", DataRowVersion.Current)
            db.AddInParameter(update, "tennxb", DbType.String, "TenNXB", DataRowVersion.Current)
            db.AddInParameter(update, "diachi", DbType.String, "DiaChi", DataRowVersion.Current)
            db.AddInParameter(update, "sodt", DbType.String, "SoDT", DataRowVersion.Current)
            db.AddInParameter(update, "email", DbType.String, "Email", DataRowVersion.Current)

            db.UpdateDataSet(ds, "NXB", insert, update, delete, UpdateBehavior.Standard)
            MessageBox.Show("Lưu thành công...!")
            frmQuanLyNXB_Load(sender, e)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btThoat.Click
        Me.Close()
    End Sub
End Class